package com.daiqile.myinterest.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.daiqile.myinterest.R;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.daiqile.myinterest.R.id.collapsing;

public class CoordinatorActivity extends AppCompatActivity {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.imageView)
    ImageView imageView;
    @BindView(collapsing)
    CollapsingToolbarLayout collapsingToolbarLayout;
    @BindView(R.id.appbar)
    AppBarLayout appbar;
    @BindView(R.id.coordinator)
    CoordinatorLayout coordinator;
    @BindView(R.id.tv_toolbar)
    TextView tvToolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_coordinator);
        ButterKnife.bind(this);
        setSupportActionBar(toolbar);
        ActionBar actionbar = getSupportActionBar();
        if (actionbar != null) {
            actionbar.setDisplayHomeAsUpEnabled(true);
        }
        //初始颜色
        collapsingToolbarLayout.setExpandedTitleColor(Color.WHITE);
        //折叠后颜色
        collapsingToolbarLayout.setCollapsedTitleTextColor(Color.BLACK);
        appbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                //verticalOffset为垂直偏移量
                if (getSupportActionBar().getHeight() - appBarLayout.getHeight() == verticalOffset) {
                            tvToolbar.setVisibility(View.VISIBLE);
                }else {
                    tvToolbar.setVisibility(View.GONE);
                }
            }
        });
    }
}
